package com.example.house.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.house.databinding.ItemHouseOneBinding
import com.example.house.databinding.ItemPeopleOneBinding
import com.example.house.databinding.ItemPeopleTwoBinding
import com.example.house.entity.People
import com.example.house.entity.PeopleEntity

class ZuHuAdapter(private val data:List<PeopleEntity>):RecyclerView.Adapter<ZuHuAdapter.ZuHuViewHolder>() {
    inner class ZuHuViewHolder(val itemDataBinding: ItemPeopleOneBinding):RecyclerView.ViewHolder(itemDataBinding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ZuHuViewHolder {
        return ZuHuViewHolder(ItemPeopleOneBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun onBindViewHolder(holder: ZuHuViewHolder, position: Int) {
        holder.itemDataBinding.tvA.text = data[position].people
        val rv = holder.itemDataBinding.rvPeople
        val peopleAdapter = PeopleAdapter(data[position].list)
        rv.adapter = peopleAdapter
        peopleAdapter.notifyDataSetChanged()
    }

}
class PeopleAdapter(private val data:List<People>):RecyclerView.Adapter<PeopleAdapter.PeopleViewHolder>() {
    inner class PeopleViewHolder(val itemPeopleTwoBinding: ItemPeopleTwoBinding):RecyclerView.ViewHolder(itemPeopleTwoBinding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PeopleViewHolder {
        return PeopleViewHolder(ItemPeopleTwoBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun onBindViewHolder(holder: PeopleViewHolder, position: Int) {
        holder.itemPeopleTwoBinding.tvCompany.text = data[position].name
    }
}